package com.zzt.appframe8

import android.os.Bundle
import android.text.*
import android.text.style.CharacterStyle
import android.util.Log
import android.widget.ArrayAdapter
import androidx.annotation.NonNull
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.textfield.TextInputLayout
import com.zzt.appframe8.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity() {
    val TAG = MainActivity::class.java.simpleName
    var textInputLayout: TextInputLayout? = null
    lateinit var bindIng: ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        bindIng = ActivityMainBinding.inflate(layoutInflater)
        setContentView(bindIng.root)
        initView()
    }

    private fun initView() {

        bindIng.tilLayout.error = "XXXXXXXXxx"


        val fromHtml1 = Html.fromHtml(resources.getString(R.string.s6_224))

        val links1 = fromHtml1.getSpans(0, fromHtml1.length, Spannable::class.java)
        Log.d(TAG, ">>> 1 " + links1.size)

        val spanStart = fromHtml1.getSpanStart(TextUtils.TruncateAt.MARQUEE)
        Log.d(TAG, ">>> 1 spanStart $spanStart")

        bindIng.tvTitle.text = fromHtml1

        val fromHtml2: Spanned = Html.fromHtml(resources.getString(R.string.s6_429))
        val links2 = fromHtml2.getSpans(0, fromHtml2.length, CharacterStyle::class.java)
        Log.d(TAG, ">>> 2 " + links2.size)
        val spanStart2 = fromHtml2.getSpanStart(TextUtils.TruncateAt.MARQUEE)
        Log.d(TAG, ">>> 2 spanStart $spanStart2")
        Log.d(TAG, ">>> 2 Spanned Count : ${fromHtml2} ")

        var spannableString: SpannableString = SpannableString(fromHtml2)
        val spanStart3 = spannableString.getSpanStart(CharacterStyle::class.java)
        Log.d(TAG, ">>> spanStart3 : ${spanStart3} ")


        val fromHtml3 = Html.fromHtml(resources.getString(R.string.s6_224).replace("\n", "<br/>"))
        bindIng.tvV3.text = fromHtml3

        bindIng.tvContent.text = fromHtml2
        bindIng.tvContent.inputType = InputType.TYPE_TEXT_VARIATION_PASSWORD

        // 设置删除按钮
        bindIng.mtilTest.setEnableClear(true)
//
//        // 设置密码输入
        bindIng.mtilTest.setEnablePassword(true)
        // 设置删除按钮
        bindIng.mtilTest2.setEnableClear(true)

        // 设置密码输入
        bindIng.mtilTest2.setEnablePassword(true)
        bindIng.button20.setOnClickListener {

            bindIng.mtilTest.setError("fffffffffffsd")
            bindIng.mtilTest2.setError("dddsfsfsdfsaf")

        }
        bindIng.button21.setOnClickListener {

            bindIng.mtilTest.setError("")
            bindIng.mtilTest2.setError("")

        }


        bindIng.button22.setOnClickListener {
            SSSSS.start(this)
        }


        val arr = arrayOf(
            "aaaaaaa",
            "bbbbbbbb",
            "ccccccc",
            "aaabbbb",
            "aaacccc",
            "bbbbaaaaaa",
            "bbbbcccc",
            "ccccbbb"
        )
        val arrayAdapter = ArrayAdapter(this, android.R.layout.simple_expandable_list_item_1, arr)
        bindIng.actvInput.setAdapter(arrayAdapter)

    }

}